<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<script type="text/javascript" src='../js/mui.min.js'></script>
		<title>主页</title>
		<script>
//			mui.init({
//			  pullRefresh : {
//			    container:".refresh",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
//			    down : {
//			      style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
//			      color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
//			      height:'50px',//可选,默认50px.下拉刷新控件的高度,
//			      range:'100px', //可选 默认100px,控件可下拉拖拽的范围
//			      offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
//			      auto: false,//可选,默认false.首次加载自动上拉刷新一次
//			      callback :refresh_now //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
//			    }
//			  }
//			});

			mui.init({
			  pullRefresh : {
			    container:'.pull_more',//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
			    up : {
			      height:50,//可选.默认50.触发上拉加载拖动距离
			      auto:false,//可选,默认false.自动上拉加载一次
			      contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
			      contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
			      callback :pullfresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
			    }
			  }
			});
			
//			function refresh_now(){
//				$(".bgsearch_body").children().remove();
//				
//				do_search(1,1)
//			}
//			
			function pullfresh() {
				var page = $("#now_page").html();
				do_search(page,2);
			     //1、加载完新数据后，必须执行如下代码，true表示没有更多数据了：
			     //2、若为ajax请求，则需将如下代码放置在处理完ajax响应数据之后
			     
			     this.endPullupToRefresh(true|false);
			}
			
			
			
			
			var qw = 1;
			var uid = window.localStorage["uid"];
			var down = getUrlParam('down');
			if(down == 1){
				alert('下载完成');
			}
			$(function(){
				do_search(1,0);
				$("body").on('click', ".bgsearch_main", function() {
                    if(qw == 1){
                        $(this).find(".disnone").show();
                        $(this).css("background","#279EEE");
                        $(this).css("color","#fff");
                        $(this).find(".bgsearch_main_hang").css("border-bottom","1px solid #fff");
                        qw = 2;
                    } else{
                        $(".bgsearch_main").find(".disnone").hide();
                        $(".bgsearch_main").css("background","#fff");
                        $(".bgsearch_main").css("color","#BCBCBC");
                        $(".bgsearch_main").find(".bgsearch_main_hang").css("border-bottom","1px solid #BCBCBC");
                        qw = 1;
                    }
                    
                });
			})
			function do_search(page,is_ref){
				var arr = new Array();
                arr[null] = "非APP运单";
                arr[0] = "未付款或者开单失败";
                arr[1] = "提交成功";
                arr[2] = "开单成功";
                arr[21] = "开单失败";
                arr[22] = "开单失败";
                arr[3] = "投保成功";
                arr[31] = "投保失败";
                
                var refunds = new Array();
                refunds[0] = "不申请";
                refunds[1] = "申请中";
                refunds[2] = "申请中";
                refunds[3] = "申请成功";
                fade_out_pull("fade_out_loading")
                $.ajax({
                    url: "http://insure.unair.cn/alipay_search.php?uid="+uid+"&page="+page,
                    type: "POST",
                    data: {
                    	uid:uid,
                    	page:page
                    },
                    success: function(data) {
                          data = eval("(" + data + ")");
//                        alert(JSON.stringify(data[0]['0']));return;
                        var item = '';
                        if(data != null){
                        	$.each(data, function(k, v) {
	                            v.refund_result = typeof (v.refund_result) == 'undefined' ? '' : v.refund_result;
	                            v.refund_result = v.refund_result == null ? '' : v.refund_result;
	                            v.certificateNo = typeof (v.certificateNo) == 'undefined' ? '' : v.certificateNo;
	                            v.certificateNo = v.certificateNo == null ? '' : v.certificateNo;
	                            v.CHEGUAHAO = typeof (v.CHEGUAHAO) == 'undefined' ? '' : v.CHEGUAHAO;
	                            v.CHEGUAHAO = v.CHEGUAHAO == null ? '' : v.CHEGUAHAO;
	                           item += '<div class="bgsearch_main">' +
	                           				'<div style="display:none" class="bgsearch_main_hang">' +
	                                            '<div class="bgsearch_main_left">RID:</div>' +
	                                            '<div class="bgsearch_main_right rid">' + v['0'] + '</div>' +
	                                        '</div>' +
	                           				'<div class="bgsearch_main_hang">' +
	                                            '<div class="bgsearch_main_left">支付宝订单号:</div>' +
	                                            '<div class="bgsearch_main_right apid">' + v.APID + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang">' +
	                                            '<div class="bgsearch_main_left">运单号:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.BGID + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang">' +
	                                            '<div class="bgsearch_main_left">服务费:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.Insurance2 + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang">' +
	                                            '<div class="bgsearch_main_left">运单状态:</div>' +
	                                            '<div style="display:none" class="hidden_div">'+v.State+'</div>'+
	                                            '<div class="bgsearch_main_right state">' + arr[v.State] + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">服务号:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.certificateNo + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">始发城市:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.FromArea + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">目的城市:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.ToArea + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">车牌号:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.PlateNo + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">车挂号:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.CHEGUAHAO + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">司机姓名:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.DriverName + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">司机电话:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.DriverMobile + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">电子凭证:</div>' +
	                                            '<div class="bgsearch_main_right down_url" >下载凭证</div>' +
	                                            '<div style="display:none" class="p_url" >' + v.policyDownloadUrl + '</div>' +
//	                                            '<div class="bgsearch_main_right"><a href="' + v.PolicyDownloadUrl + '">电子凭证</a></div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">运费:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.Freight + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">提交时间:</div>' +
	                                            '<div class="bgsearch_main_right">' + v.CreateOn.date + '</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">&nbsp;</div>' +
	                                            '<div class="bgsearch_main_right refunds">申请退款</div>' +
	                                        '</div>' +
	                                        '<div class="bgsearch_main_hang disnone">' +
	                                            '<div class="bgsearch_main_left">申请结果:</div>' +
	                                            '<div class="bgsearch_main_right refunds_result">' + refunds[v.refunds] + '</div>' +
	                                        '</div>' +
	                                '</div>';
	                        });
	                        $('.bgsearch_body').append(item);
                        }
	                        
//                      if(is_ref == 1){
//                      	mui('.refresh').pullRefresh().endPulldown();
//                      }
                        if(is_ref == 2){
                        	if(data == null || data == undefined){
                        		mui('.pull_more').pullRefresh().endPullupToRefresh(true);
                        	}else{
                        		mui('.pull_more').pullRefresh().endPullupToRefresh(false);
                        	}
//							mui('.pull_more').pullRefresh().endPullupToRefresh(false);
                        	
                        }
                        
                        
                    },
                    error: function(data) {
//                        alert("刷新失败")
                    }
                });
                fade_out_hide();
                $("#now_page").html(page + 1);
			}
			
			$(function(){
				$("body").on("click",".down_url",function(){
					var url = $(this).parent().find('.p_url').html();
					clicked('./policyurl.html?url=' + url)
				});
				
				$("body").on("click",".refunds",function(){
					var state=$(this).parent().parent().find('.hidden_div').html();
					if(state==0){
						var refunds_result=$(this).parent().parent().find('.refunds_result').html();
						if(refunds_result=='申请中'){
							alert('已在退款中，不可再操作！');
							return ;
						}
						var apid=$(this).parent().parent().find('.apid').html();
						var rid = $(this).parent().parent().find('.rid').html();
						clicked('applyreason.html?apid='+apid+'&rid='+rid);
					}else{
						alert('对不起，您不符合申请条件！');
					}
					
//					alert(rid);return;
//					$.ajax({
//                  url: "http://insure.unair.cn/refunds.php",
//                  type: "POST",
//                  data: {
//                  	rid:rid
//                  },
//                  success: function(data) {
//                      //alert('申请成功')
//                  },
//                  error: function(data) {
//						//alert('申请失败')
//                  }
//              });

				});
			});
			
				
		</script>
	</head>
	<body>
		
		<div class="app_head">
            <div class="app_prev" onclick="clicked('../index.html')"><img src="../img/arrow.png" /></div>
            <div class="app_head_text">开单记录</div>
            <div class="app_prev"></div>
        </div>
        <div class="refresh"></div>
        <div class="bgsearch_body"></div>
        <dv class='pull_more'></dv>
        <div style="display: none" id="now_page"></div>

<div class="outside_pull"></div>
<img src="../img/loading.gif" class="fade_out_img" id="fade_out_loading" />
	</body>
</html>
